import threading
def worker(num1, num2):
    """线程工作函数"""
    print(f'Worker {num1} is running {num2  }')# 模拟一些工作

# 1 创建线程,使用函数
thread1 = threading.Thread(target=worker, args=(1,2))
thread1.start()
thread1.join()  # 等待线程完成

# 2 创建线程对象，使用lambda表达式
thread2 = threading.Thread(target=lambda: print('Worker is done'))
thread2.start()
thread2.join()  

# 3 创建线程类，继承自threading.Thread
class MyThread(threading.Thread):
    def __init__(self, name):
        super().__init__()
        self.name = name

    def run(self):
        print(f'MyThread {self.name} is running')

thread3 = MyThread('Thread 3')
thread3.start()
thread3.join()